package com.example.message.controller;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.message.entity.Notice;
import com.example.message.service.NoticeService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/notice")
public class NoticeController {

	private final NoticeService noticeService;

	/**
	 * 分页查询
	 * @param page 分页对象
	 * @param sysNotice 数据源表
	 * @return
	 */
	@GetMapping("/page" )
	public R getGenDatasourceConfPage(Page page, Notice sysNotice) {
		return R.ok(noticeService.page(page, Wrappers.query(sysNotice)));
	}


	/**
	 * 通过id查询数据源表
	 * @param id id
	 * @return R
	 */
	@GetMapping("/{id}" )
	public R getById(@PathVariable("id" ) Integer id) {
		return R.ok(noticeService.getById(id));
	}

	/**
	 * 新增数据源表
	 * @param sysNotice 数据源表
	 * @return R
	 */
	@PostMapping
	public R save(@RequestBody Notice sysNotice) {
		System.out.println("aa:"+sysNotice.toString());
		return R.ok(noticeService.save(sysNotice));
	}

	/**
	 * 修改数据源表
	 * @param sysNotice 数据源表
	 * @return R
	 */
	@PutMapping
	public R updateById(@RequestBody Notice sysNotice) {
		return R.ok(noticeService.updateById(sysNotice));
	}

	/**
	 * 通过id删除数据源表
	 * @param id id
	 * @return R
	 */
	@DeleteMapping("/{id}" )
	public R removeById(@PathVariable Integer id) {
		return R.ok(noticeService.removeById(id));
	}


	/**
	 * 获得新闻列表
	 * @return List
	 */
	@GetMapping("/getNoticeList")
	public R getNoticeList() {
		return R.ok(noticeService.getNoticeList());
	}


}
